﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script>
        $(function () {

            $(".btn-edit").click(function () {
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if(json){
                    $("input[name=id]").val(json.id);
                    $("input[name=name]").val(json.name);
                    $("input[name=sn]").val(json.sn);
                }
                $("#myModal").modal("show");
            });
            //编辑保存部门
            $(".btn-submit").click(function () {

                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        msg("保存成功");
                    }else {
                        $.messager.alert(data.msg);
                    }
                });
            });
            //删除部门
            $(".btn-delete").click(function () {
                var url = $(this).data("url");
                $.messager.confirm("注意","确定要删除这条数据吗？",function () {
                    $.get(url,function (data) {
                        if(data.success){
                           // 提示信息函数，编写在header.ftl中
                           msg("删除成功");
                        }else{
                            $.messager.alert(data.msg);
                        }
                    });
                });
            });
        });



    </script>
</head>
<body>

<div class="container-fluid" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-2">
            <#--设置当前要回显当前菜单,必须在载入菜单前完成设置-->
            <#assign menu="department"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">部门管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <input type="hidden" name="pageSize" id="pageSize" value="20">
                <a class="btn btn-success btn-edit">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>部门名称</th>
                    <th>部门编号</th>
                    <th>操作</th>
                </tr>
                <#list (ro.list)! as dept>
                    <tr>
                       <td>${(dept_index+1)!}</td>
                       <td>${(dept.name)!}</td>
                       <td>${(dept.sn)!}</td>
                       <td>
                           <@shiro.hasPermission name="department:input">
                               <a class="btn btn-info btn-xs btn-edit" data-json='${(dept.json)!}'>
                                   <span class="glyphicon glyphicon-pencil"></span> 编辑
                               </a>
                           </@shiro.hasPermission>
                           <@shiro.hasPermission name="department:delete">
                               <a class="btn btn-danger btn-xs btn-delete" data-url='/department/delete.do?id=${(dept.id)!}' >
                                   <span class="glyphicon glyphicon-trash"></span> 删除
                               </a>
                           </@shiro.hasPermission>
                       </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">部门信息编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id" value="${(entity.id)!}">
                    <div class="form-group" >
                        <label class="col-lg-3 control-label">部门名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" value="${(entity.name)!}"
                                   placeholder="请输入部门的名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-3 control-label">部门编号：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="sn" value="${(entity.sn)!}"
                                   placeholder="请输入部门编号">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">提交</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
       $("#editForm").validate({
          rules:{
              name:{
                  required:true
              },
              sn:{
                  required:true
              }
          },
           messages:{
               name:{
                   required:"不能为空"
               },
               sn:{
                   required:"不能为空"
               }
           }
       });
    });

</script>


</body>
</html>